<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //写入5行4列的表格，将帖子数组中数据填充到单元格中
    var arr = [
        ["第1条帖子","a","第1条帖子……","2011-02-14"],
        ["第2条帖子","b","第2条帖子……","2011-02-01"],
        ["第3条帖子","c","第3条帖子……","2011-02-23"],
        ["第4条帖子","a","第4条帖子……","2011-02-06"],
        ["第5条帖子","d","第5条帖子……","2011-02-18"],
    ]


    var tbHeight = "500px";
    var tbWidth = "800px";

    document.write("<table border='1' height ='"+tbHeight+"'width = '"+tbWidth+"'>");

    function creatList(arr){
        for(var i =0;i<arr.length;i++){
            document.write("<tr>");
            for(var j=0;j<arr[0].length;j++){
                if(j==2){
                    arr[i][j]=arr[i][j].slice(0,5)+"...";
                }
                document.write("<td>");
                document.write(arr[i][j]);
                document.write("</td>");
        }
        document.write("</tr><br/>");
        }
    }
 
    creatList(arr);
    document.write("</table>");





    //截取前5个字符，后面内容用...代替
    // var text = "这是帖子5，主要内容是";

    // var preview = text.slice(0,5);
    // preview = preview + "...";
    // document.write(preview);
</script>
</html>